package algorithm.poj.p1000;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;


/**
 * 分析：
 * 
 * 实现：
 * 
 * 经验和教训：
 * 
 * 
 * @author wong.tong@gmail.com
 *
 */
public class P1573 {

	public static void main(String[] args) throws Exception {

		InputStream input = null;
		if (false) {
			input = System.in;
		} else {
			URL url = P1573.class.getResource("P1573.txt");
			File file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
			input = new FileInputStream(file);
		}
		
		BufferedReader stdin = new BufferedReader(new InputStreamReader(input));

		String line = stdin.readLine().trim();
		while (line != null && !"0 0 0".equals(line)) {
			String[] tmp = line.split(" ");
			int H = Integer.valueOf(tmp[0]);
//			int W = Integer.valueOf(tmp[1]);
			int R = 0;
			int C = Integer.valueOf(tmp[2])-1;
			
			Position pos = new Position(C, R);
			
			char[][] grid = new char[H][]; 
			for (int i = 0; i < H; i ++) {
				line = stdin.readLine();
				grid[i] = line.toCharArray();
			}
			System.out.println(motion(grid, pos));
			line = stdin.readLine().trim();
		}
	}
	
	private static String motion(char[][] grid, Position pos) {
		
		List<Position> positions = new ArrayList<Position>();
		positions.add(pos);
		
		Position cp = pos;
		Position np = null;
		while (true) {
			np = cp.next(grid[cp.y][cp.x]);
			if (np.exit(grid.length, grid[0].length)){
				return positions.size() + " step(s) to exit";
			} else {
				for (int i = 0; i < positions.size(); i ++) {
					if (np.equals(positions.get(i))) {
						return i + " step(s) before a loop of " + (positions.size()-i) + " step(s)";
					}
				}
				cp = np;
				positions.add(np);
			}
		}
	}

	private static class Position {
		
		int x;
		int y;
		
		Position(int x, int y) {
			this.x = x;
			this.y = y;
		}
		
		Position next(char ins) {
			
			Position pos = new Position(this.x, this.y);
			switch (ins) {
			case 'N': pos.y --; break;
			case 'S': pos.y ++; break;
			case 'W': pos.x --; break;
			case 'E': pos.x ++; break;
			}
			return pos;
		}
		
		@Override
		public boolean equals(Object obj) {
			
			if (obj == null || !(obj instanceof Position)) {
				return false;
			} else {
				Position p = (Position)obj;
				return p.x== this.x && p.y == this.y;
			}
		}
		
		public boolean exit(int H, int W) {
			
			return (this.x < 0 || this.x > W-1) || (this.y < 0 || this.y > H-1);
		}
		
		@Override
		public String toString() {
			return "(" + y + ", " + x + ")";
		}
	}
}